import {Component} from '@angular/core';
import {Router} from '@angular/router';
import {Message} from 'primeng/primeng';
import {Http} from '@angular/http'
import {User} from "./user/model/user-model";
import {UserLoginService} from "./user/user-login/user-login.service";
import {UserRegisterService} from "./user/user-register/user-register.service";

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  title = 'app';
  public msgs: Message[] = [];
  public currentUser: User;


  constructor(public router: Router,
              public userLoginService:UserLoginService,
              public userRegisterService:UserRegisterService
              ) {

  }
  ngOnInit(){
    console.log('appcomponent init----->>>');
    this.currentUser = new User();
    this.currentUser = JSON.parse(localStorage.getItem("currentUser"));
    this.userLoginService.currentUser
      .merge(this.userRegisterService.currentUser)
      .subscribe(data=>{
      this.currentUser = data;
    })
  }

  public doLogout(): void {
    this.userLoginService.logout();
    this.msgs = [];
    this.msgs.push({severity: 'success', summary: 'Success Message', detail: '退出成功'});
    this.router.navigateByUrl("");
  }


  toggle(button: any) {
    console.log(button);
  }
}
